<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <script src="https://cdn.bootcdn.net/ajax/libs/angular.js/1.6.8/angular.min.js"></script>
  </head>
  <body>
    <div ng-app="myApp" ng-controller="myCtrl">
      <h1>{{indexName}}</h1>
      <!-- 自定义组件 -->
      <hello></hello>
    </div>

    <script>
      var app = angular.module("myApp", []);
      app.controller("myCtrl", function ($scope) {
        $scope.indexName = "主页";
      });
      // 第一个组件
      app.component("hello", {
        template: `
            <div>
                <h3>Hello</h3>
                <world></world>
            </div>
        `,
        controller: function ($scope) {
          this.$onInit = function () {
            console.log("hello init");
          };
        },
      });
      // 第二个组件
      app.component("world", {
        template: `
            <div>
                <h4>World</h4>
            </div>
        `,
        controller: function ($scope) {
          this.$onInit = function () {
            console.log("world init");
          };
        },
      });
    </script>
  </body>
</html>
